package com.changwu.cwbase.ui.commont;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.blankj.utilcode.util.FragmentUtils;
import com.blankj.utilcode.util.StringUtils;
import com.changwu.cwbase.Constants;
import com.changwu.cwbase.R;
import com.changwu.cwbase.base.ActivityBase;


/*
 * 通用使用模板
 */
public class CommonFragmentActivity extends ActivityBase {
    private Fragment mFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);
        initView();
    }

    @Override
    public void initToolBar() {
        super.initToolBar();
        title.setText("模板");
    }

    private void initView() {
        Intent intent = getIntent();
        String fragmentName = intent.getStringExtra(Constants.ID);
        if (StringUtils.isEmpty(fragmentName)) {
            return;
        }
        final String FRAG_TAG = "fragment-tag";
        mFragment = getSupportFragmentManager().findFragmentByTag(FRAG_TAG);
        if (mFragment == null) {
            mFragment = Fragment.instantiate(this, fragmentName,
                    intent.getExtras());
            if (mFragment == null) {
                return;
            }
            mFragment.setArguments(intent.getExtras());
        }
        FragmentUtils.replace(getSupportFragmentManager(), mFragment, R.id.fl_content);
    }

   /* @OnClick({R.id.back})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;
        }
    }*/
}
